fn main() {
    // loop
    'outer: loop {
        println!("outer");
        loop {
            println!("inner");
            break 'outer;
        }
    }

    // while
    let mut i = 0;
    while i <= 5 {
        println!("i: {}", i);
        i += 1;
    }

    // for
    let arr = [1, 2, 3, 4, 5];
    for i in arr {
        println!("i: {}", i);
    }

    // for with range
    for i in 0..=5 {
        println!("i: {}", i);
    }

    // for with range and step
    for i in (0..=5).step_by(2) {
        println!("i: {}", i);
    }

    // for with range and reverse
    for i in (0..=5).rev() {
        println!("i: {}", i);
    }

    // break
    let mut i = 0;
    for _ in 0..=5 {
        i += 1;
        if i == 3 {
            break;
        }
        println!("i: {}", i);
    }

    // continue
    let mut i = 0;
    for _ in 0..=5 {
        i += 1;
        if i == 3 {
            continue;
        }
        println!("i: {}", i);
    }

    // 循环写法
    let mut result = Vec::new();
    let arr = [1, 2, 3, 4, 5];
    for i in arr.iter() {
        result.push(i * i)
    }
    println!("result for: {:?}", result);

    // 迭代写法（坑：在Windows上使用GNU工具链，下面的代码会编译失败） 
    let arr = [1, 2, 3, 4, 5].to_vec();
    let result: Vec<_> = arr.iter().map(|i| i * i).collect();
    println!("result iter: {:?}", result);
}
